﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using PQT.API;
using PQT.Controls;
using PQT.API.File;
using cbmobile.BLC;

namespace cbmobile.UserControl
{
    public partial class LoaiPhuKien_List : CommonUserControl
    {
        int pagesize = 10;
        BLC_LoaiPhuKien blc = new BLC_LoaiPhuKien();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGirdView();
            }
        }

        private int CurrentPage
        {
            get
            {
                if (ViewState["g_CurrentPage"] != null)
                    return Convert.ToInt32(ViewState["g_CurrentPage"]);
                return 1;
            }
            set
            {
                ViewState["g_CurrentPage"] = value;
            }
        }


        private void BindGirdView()
        {
            gvList.DataSource = blc.Row_LoaiPhuKien(txtSearch.Text);
            gvList.DataBind();

            
        }

        public int numpage()
        {
            int page = this.CurrentPage;
            int pagesize = 10;

            if (page > 1)
                return ((Convert.ToInt16(page) * pagesize - pagesize) > 0) ? (Convert.ToInt16(page) * pagesize - pagesize) : 0;
            return 0;
        }

        protected string StatusName(object StatusID)
        {
            return StatusID != null ? ((CommonStatus)StatusID).ToString() : string.Empty;
        }

        

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindGirdView();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteItem")
            {
                blc.Delete(Convert.ToInt32(e.CommandArgument));
                BindGirdView();
            }
            if (e.CommandName == "ViewList")
            {
                Response.Redirect(String.Format("/RenderMain.aspx?muid=LoaiPhuKien_Entry&Ma_LoaiPhuKien={0}", e.CommandArgument));
            }
        }
    }
}